package edu.misaka.moe.service;

import java.util.List;
import java.util.Map;

import edu.misaka.moe.dao.UserDaoImpl;
import edu.misaka.moe.dao.iface.UserDao;
import edu.misaka.moe.domain.Page;
import edu.misaka.moe.domain.UMQueryKeyword;
import edu.misaka.moe.domain.User;
import edu.misaka.moe.domain.UserDetail;

import edu.misaka.moe.service.iface.UserService;
import edu.misaka.moe.utils.TransactionManager;

public class UserServiceImpl implements UserService{
	UserDao userdao=new UserDaoImpl();

	public boolean login(String name, String password) {
		boolean flag=false;
		
		if(userdao.queryUser(name, password)==1) {
			flag=true;
		}
		return flag;
	}

	@Override
	public boolean insertUser(User user) {
		boolean flag=false;
		int rowNum=userdao.upUser(user);
		if(rowNum==1) {
			flag=true;
		}
		return flag;
	}

	@Override
	public boolean insertUserDetail(UserDetail ud) {
		boolean flag=false;
		int rowNum=userdao.upUserDetail(ud);
		if(rowNum==1) {
			flag=true;
		}
		return flag;
	}

	@Override
	//将用户表和城市&爱好表添加到数据库的事件
	public boolean register(User user, UserDetail ud) {
		boolean flag=false;
		TransactionManager tm=new TransactionManager();
		tm.beginTranscation();
			int userId=userdao.upUser(user);
			ud.setUserId(userId);
			int rowNum=userdao.upUserDetail(ud);
		tm.commitAndClose();
		if(userId!=-1&&rowNum!=0) {
			flag=true;
		}
		return flag;
	}

	@Override
	public void showByPage(Page<List<Map<String, Object>>> page) {
		userdao.queryByPage(page);
		
	}

	@Override
	public void getTotalRow(Page<List<Map<String, Object>>> page) {
		userdao.getTotalRow(page);
		
	}

	@Override
	public void showByPage(Page<List<Map<String, Object>>> page, UMQueryKeyword qk) {
		userdao.queryByPage(page,qk);
		
	}

	@Override
	public void getTotalRow(Page<List<Map<String, Object>>> page, UMQueryKeyword qk) {
		userdao.getTotalRow(page,qk);

		
	}

	
}
